package com.newsee.remote.common.exception;

import com.newsee.remote.common.bean.JsonResult;
import com.newsee.remote.common.bean.JsonReturn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 *
 * @author liangzhichen
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 业务异常处理
     **/
    @ExceptionHandler(value = ServiceException.class)
    @ResponseBody
    public JsonResult serviceHandler(ServiceException e) {
        log.warn("ServiceException  message {}  cause {} e {} ", e.getMessage(), e.getCause(), e.toString());
        return JsonReturn.fail(e.getMessage());
    }

}
